package com.kapcb.assemble.strategy;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * <a>Title: AbstractStrategySelector </a>
 * <a>Author: Kapcb <a>
 * <a>Description: 抽象策略类选择器 <a>
 *
 * @author Kapcb
 * @version 1.0
 * @date 2024/4/17 22:37
 * @since 1.0
 */
public abstract class AbstractStrategySelector implements IStrategy {

    @Override
    public <T> void accept(String bizCode, Consumer<T> consumer) {
        T t = selectStrategy(bizCode);
        consumer.accept(t);
    }

    @Override
    public <T, R> R apply(String bizCode, Function<T, R> function) {
        T t = selectStrategy(bizCode);
        return function.apply(t);
    }

    /**
     * 根据 bizCode 选择策略
     *
     * @param bizCode
     * @param <T>
     * @return
     */
    protected abstract <T> T selectStrategy(String bizCode);
}
